package com.dwy2002.enums;

import lombok.Getter;

import java.util.Arrays;

/**
 * 任务状态枚举
 *
 * @author 杜伟毅
 * @version 1.0
 * @since 2025/07/17
 */
@Getter
public enum TaskState {
    PUBLISHED(1, "已发布"),
    ONGOING(2, "进行中"),
    WAITING_REVIEW(3, "等待审核"),
    COMPLETED(4, "已完成"),
    DELAYED(5, "已延期"),
    CLOSED(6, "已关闭");

    private final int code;
    private final String description;

    TaskState(int code, String description) {
        this.code = code;
        this.description = description;
    }

    /**
     * 通过code获取枚举
     *
     * @param code 状态数字
     * @return 对应的枚举
     * @author 杜伟毅
     * @since 2025/7/17 0017 11:24
     */
    public static TaskState fromCode(int code) {
        return Arrays.stream(values())
                .filter(state -> state.code == code)
                .findFirst()
                .orElseThrow(() -> new IllegalArgumentException("非法状态码: " + code));
    }
}
